<?php

/**
 * Common code for Route test cases.
 */



function testRouteIn(Route $route, $uri)
{
	T::note("==> $uri");

	$uri = new UriScript("http://example.com$uri");
	$uri->scriptPath = '/';
	$uri->appendQuery(array(
		'test' => 'testvalue',
		'presenter' => 'querypresenter',
	));

	$httpRequest = new HttpRequest;
	$httpRequest->initialize();
	$httpRequest->setUri($uri);

	$request = $route->match($httpRequest);

	if ($request) { // matched
		$params = $request->getParams();
		//asort($params);
		T::dump( $request->getPresenterName() );
		T::dump( $params );

		unset($params['extra']);
		$request->setParams($params);
		$result = $route->constructUrl($request, $httpRequest);
		$result = strncmp($result, 'http://example.com', 18) ? $result : substr($result, 18);
		T::dump( $result );

	} else { // not matched
		T::note('not matched');
	}
}



function testRouteOut(Route $route, $link, $params = array())
{
	T::note("==> [$link]");

	$uri = new UriScript("http://example.com");
	$uri->scriptPath = '/';
	$httpRequest = new HttpRequest;
	$httpRequest->initialize();
	$httpRequest->setUri($uri);

	$request = new PresenterRequest($link, 'GET', $params);
	$result = $route->constructUrl($request, $httpRequest);

	T::dump( $result );
}

